package library.push.receiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

import cn.jpush.android.api.JPushInterface;
import library.push.NotificationUtils;

public class JPushDataReceiver extends BroadcastReceiver {

    private static final String TAG = "JPush";

    @Override
    public void onReceive(Context context, Intent intent) {
        if (intent == null || intent.getAction() == null) return;
        if (JPushInterface.ACTION_REGISTRATION_ID.equals(intent.getAction())) {
            String pushId = intent.getStringExtra(JPushInterface.EXTRA_REGISTRATION_ID);
            Log.d(TAG, "用户注册成功, registerId:" + pushId);
        } else if (JPushInterface.ACTION_MESSAGE_RECEIVED.equals(intent.getAction())) {
            Log.d(TAG, "自定义消息");
            /*
             * modified by qiang.hou on 2018.04.28 for reject push when logout
             */
            NotificationUtils.dealPushMessage(context, true, intent.getExtras());
        } else if (JPushInterface.ACTION_NOTIFICATION_RECEIVED.equals(intent.getAction())) {
            Log.d(TAG, "推送通知");
        } else if (JPushInterface.ACTION_NOTIFICATION_OPENED.equals(intent.getAction())) {
            Log.d(TAG, "点击打开Notification id = " + intent.getStringExtra(JPushInterface.EXTRA_REGISTRATION_ID));
            NotificationUtils.dealPushMessage(context, false, intent.getExtras());
        } else if (JPushInterface.ACTION_CONNECTION_CHANGE.equals(intent.getAction())) {
            Log.d(TAG, "network connected = " + intent.getBooleanExtra(JPushInterface.EXTRA_CONNECTION_CHANGE, false));
        } else {
            Log.d(TAG, "JPUSHUnhandled intent - " + intent.getAction());
        }
    }
}
